﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Text;
using QuanLiSinhVien_v01.DAO;
using QuanLiSinhVien_v01.DTO;

namespace QuanLiSinhVien_v01.BUS.Pattern
{
    class InfoOfClassStrategy: InfoStrategy
    {
        public override Object[] Explore()
        {
            Object[] result;
            LopHocDao lophocDAO = new LopHocDao();
            result = lophocDAO.GetList();
            return result;
        }
        public override Object[] Search(string keyword)
        {
            Object[] result;
            LopHocDao lophocDAO = new LopHocDao();
            result = lophocDAO.Search(keyword);
            return result;
        }
        public override void Update(Object obj)
        {
            LopHocDto lop = new LopHocDto();
            DataGridViewRow row = (DataGridViewRow)obj;
            lop.MaLopHoc = row.Cells[0].Value.ToString();
            lop.TenLopHoc = row.Cells[1].Value != null ? row.Cells[1].Value.ToString() : "";
            lop.MaKhoaHoc = row.Cells[2].Value != null ? row.Cells[2].Value.ToString() : "";
            lop.MaNganhHoc = row.Cells[3].Value != null ? row.Cells[3].Value.ToString() : "";
            lop.GhiChu = row.Cells[4].Value != null ? row.Cells[4].Value.ToString() : "";
            LopHocDao sinhvienDAO = new LopHocDao();
            sinhvienDAO.LopHoc = lop;
            sinhvienDAO.Update();
        }
        public override void Delete(Object obj)
        {
            LopHocDto lop = new LopHocDto();
            DataGridViewRow row = (DataGridViewRow)obj;
            lop.MaLopHoc = row.Cells[0].Value.ToString();
            lop.TenLopHoc = row.Cells[1].Value != null ? row.Cells[1].Value.ToString() : "";
            lop.MaKhoaHoc = row.Cells[2].Value != null ? row.Cells[2].Value.ToString() : "";
            lop.MaNganhHoc = row.Cells[3].Value != null ? row.Cells[3].Value.ToString() : "";
            lop.GhiChu = row.Cells[4].Value != null ? row.Cells[4].Value.ToString() : "";
            LopHocDao lophocDAO = new LopHocDao();
            lophocDAO.LopHoc = lop;
            lophocDAO.Delete();
        }
        public override void Insert(Object obj)
        {
            LopHocDto lop = new LopHocDto();
            lop = (LopHocDto)obj;
            LopHocDao lophocDAO = new LopHocDao();
            lophocDAO.LopHoc = lop;
            lophocDAO.Insert();
        }
    }
}
